var app = getApp()
Page({
  data: {
    shopinfo: [],
    arraydetail: [],
    productId: 0,
    productAmount: 1,
    author: 'Lotus',
    goods_id: null
  },
  onShareAppMessage: function () {
    var that = this;
    var productId = that.data.productId;
    return {
      title: app.globalData.shopName,
      path: '/pages/index/productdetail?productId=' + productId + '&fromInviteCode=' + app.globalData.myInviteCode,
      success: function (res) {
        //console.log("转发成功");
      }
    }
  },
  gotocart: function (e) {
    wx.switchTab({
      url: 'mycart'
    })
  },
  getgoodsdetail: function (e) {
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/getgoodsdetail&goodsid=' + e,
      'cachetime': '30',
      success: function (res) {
        // console.log(res.data.data);
        var goodsdetail = res.data.data;
        that.setData({
          arraydetail: goodsdetail,
        })
      }
    })
  },
  add: function (e) {
    var that = this;
    var goods_id = that.data.goods_id;
    var openid = app.globalData.openId;
    console.log(e);
    app.util.request({
      'url': 'entry/wxapp/Addcart&goodsid=' + goods_id + '&openid=' + openid,
      'cachetime': '30',
      success: function (res) {
        console.log(10);
        wx.showToast({
          title: '添加成功',
          icon: 'sucess',
          duration: 2000
        })
      },
      fail: function (res) {
        console.log("fail:" + res);
      },
    })
  }
  ,
  addnow: function (e) {
    var that = this;
    var goods_id = that.data.goods_id;
    var openid = app.globalData.openId;
    app.util.request({
      'url': 'entry/wxapp/Addcart&goodsid=' + goods_id + '&openid=' + openid,
      'cachetime': '30',
      success: function (res) {
        wx.redirectTo({
          url: 'mycart'
        })
      },
      fail: function (res) {
        wx.redirectTo({
          url: 'mycart'
        })
      },

    })


  },
  onLoad: function (options) {
    var that = this;
    var goods_id = options.productId;
    that.setData({
      goods_id: goods_id,
    })
    that.getgoodsdetail(goods_id);
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
  },

})